<!--商品（商品）-->
<meta charset="utf-8"/>
<div class="row">
  <div class="col-xs-12">
    <div class="row">
      <div class="col-xs-12">
        <div style="height:36px;margin-top:2px">
          <table class="no-border" style="display:inline">
            <tr>
              <td permission='mall_goods_btn_listData' style="padding:0 6px;display:none" class="hidden-480">
                商品名称
              </td>
              <td permission='mall_goods_btn_listData' style="display:none" class="hidden-480">
                <input type="text" id="key_name" class="form-control search-query" placeholder="输入商品名称" style="width:180px"/>
              </td>
              <td permission='mall_goods_btn_listData' style="padding:0 6px;display:none" class="hidden-480">
                销售状态
              </td>
              <td permission='mall_goods_btn_listData' style="display:none" class="hidden-480">
                <span class="input-group-btn" style="min-width:99px">
                  <button data-toggle="dropdown" class="btn btn-primary btn-white dropdown-toggle col-sm-12" style="margin-left:0px">
                    <span id="labelSearch_valid">全部状态</span>
                    <i class="ace-icon fa fa-angle-down"></i>
                  </button>
                  <ul class="dropdown-menu col-sm-12" style="width:99px;min-width:99px">
                    <li>
                      <a href="javascript:winFn.dropdown('#key_valid','','#labelSearch_valid','全部状态');">全部状态</a>
                    </li>
                    <li>
                      <a href="javascript:winFn.dropdown('#key_valid','1','#labelSearch_valid','上架状态');">上架状态</a>
                    </li>
                    <li>
                      <a href="javascript:winFn.dropdown('#key_valid','0','#labelSearch_valid','下架状态');">下架状态</a>
                    </li>
                  </ul>
                  <input id="key_valid" type="hidden"/>
                </span>
              </td>
              <td permission='mall_goods_btn_listData' style="display:none">
                <div class="input-group">
                  <span class="input-group-btn"><button type="button" class="btn btn-inverse btn-white" id="btnSearch" title="搜索查询"><span class="ace-icon fa fa-search bigger-110"></span>搜索</button></span>
                </div>
              </td>
              <td permission='mall_goods_btn_listData' style="display:none" class="hidden-480">
                <div class="input-group">
                  <span class="input-group-btn"><button type="button" class="btn btn-inverse btn-white" id="btnReset" title="重置清空搜索关键字"><span class="ace-icon fa fa-undo bigger-110"></span>重置</button></span>
                </div>
              </td>
              <td permission='mall_goods_btn_add' style="display:none">
                <div class="input-group">
                  <span class="input-group-btn"><button type="button" class="btn btn-inverse btn-white" id="btnAdd" title="新增|添加"><span class="ace-icon fa fa-plus bigger-110"></span>添加</button></span>
                </div>
              </td>
              <td permission='mall_goods_btn_delByKeys' style="display:none" class="hidden-480">
                <div class="input-group">
                  <span class="input-group-btn"><button type="button" class="btn btn-inverse btn-white" id="btnDel" title="删除|批量删除" disabled="disabled"><span class="ace-icon fa fa-trash red2 bigger-110"></span>删除</button></span>
                </div>
              </td>
            </tr>
          </table>
          <div class="hidden-480 pull-right tableTools-container" permission='mall_goods_btn_listData' style="display:none;margin-bottom:2px"></div>
        </div>
        <table id="tableListGoods" class="table table-striped table-bordered table-hover">
          <tbody>
            <tr>
              <td style="text-align:center;height:37px">正在加载……</td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
<div id="div_goods_edit" style="display:none;padding-top:2px">
  <form class="form-horizontal" id="form_goods_edit" role="form">
    <label class="col-sm-2 control-label no-padding-right"><div class="hr-4">商品名称<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
    <div class="col-sm-9">
      <div class="hr-4"></div>
      <input type="text" id="name" placeholder="商品名称" class="form-control" maxlength="128" title="商品名称"/>
    </div>
    <label class="col-sm-2 control-label no-padding-right"><div class="hr-4">商品分类<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
    <div class="col-sm-9">
      <div class="hr-4"></div>
      <div class="input-group" title="选择商品分类">
        <span class="input-group-btn">
          <button data-toggle="dropdown" class="btn btn-primary btn-white dropdown-toggle col-sm-12" style="margin-left:0px">
            <span id="labelDynamic_category">选择商品分类</span>
            <i class="ace-icon fa fa-angle-down"></i>
          </button>
          <ul class="dropdown-menu col-sm-12" id="ulDynamic_category"></ul>
          <input id="category" maxlength="19" type="hidden"/>
        </span>
      </div>
    </div>
    <label class="col-sm-2 control-label no-padding-right"><div class="hr-4" id="added_required_thumbnail">商品图片<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
    <div class="col-sm-9" id="thumbnail_parent" >
      <div class="hr-4"></div>
      <input type="file" id="thumbnail" placeholder="商品缩略图" class="form-control" title="请选择商品缩略图(单张)"/>
    </div>
    <label class="col-sm-2 control-label no-padding-right"><div class="hr-4" id="added_required_cover">介绍图<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
    <div class="col-sm-9" id="cover_parent" >
      <div class="hr-4"></div>
      <input type="file" id="cover" placeholder="商品介绍图" multiple="multiple" class="form-control" title="请选择商品介绍图(多张)"/>
    </div>
    <div id="div_default_size">
      <label class="col-sm-2 control-label no-padding-right"><div class="hr-4">商品规格<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
      <div class="col-sm-9">
        <div class="hr-4"></div>
        <input placeholder="默认的规格名称" id="default_size_name" value="默认" class="col-sm-4" type="text" maxlength="64" title="默认的规格名称"/>
        <span class="input-icon col-sm-4">
          <input placeholder="规格的价格" class="col-sm-12" style="padding-left:14px;padding-right:2px" type="text" id="default_size_price" maxlength="12" title="单个规格的价格" oninput="value=value.replace(/[^\d.]/g,'')"/>
          <i class="ace-icon fa fa-rmb blue" style="margin-top:3px;margin-left:1px"></i>
        </span>
        <input placeholder="库存量，为空为无限库存" id="default_size_inventory" class="col-sm-4" type="text" maxlength="10" title="规格库存量，为空为无限库存量" oninput="value=value.replace(/[^\d]/g,'')"/>
      </div>
    </div>
    <label class="col-sm-2 control-label no-padding-right"><div class="hr-4">注意事项<span style="display:inline-block;width:7px"></span></div></label>
    <div class="col-sm-9">
      <div class="hr-4"></div>
      <input type="text" id="tips" placeholder="注意事项|温馨提示" class="form-control" maxlength="512" title="注意事项|温馨提示"/>
    </div>
    <label class="col-sm-2 control-label no-padding-right"><div class="hr-4">商品描述<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
    <div class="col-sm-9">
      <div class="hr-4"></div>
      <textarea type="text" id="details" placeholder="商品描述" class="form-control limited" maxlength="921600000" style="width:100%;height:550px;" title="请输入商品描述"></textarea>
    </div>
    <label class="col-sm-2 control-label no-padding-right"><div class="hr-4">排序号<span style="display:inline-block;width:7px"></span></div></label>
    <div class="col-sm-9" style="margin-bottom:6px">
      <div class="hr-4"></div>
      <input type="text" id="sort" placeholder="排序号" class="form-control" maxlength="5" oninput="value=value.replace(/[^\d]/g,'')" title="排序号"/>
    </div>
  </form>
</div>
<div id="divKeyColumns" style="display:none;padding:1px 0px;"></div>
<div style="display:none;">
  <input type="hidden" id="mall_goods_btn_listData"/>
  <input type="hidden" id="mall_goods_btn_add"/>
  <input type="hidden" id="mall_goods_row_edit"/>
  <input type="hidden" id="mall_goods_row_queryById"/>
  <input type="hidden" id="mall_goods_row_valid"/>
  <input type="hidden" id="mall_goods_btn_delByKeys"/>
  <input type="hidden" id="mall_goods_row_listSpecs"/>
  <input type="hidden" id="mall_goods_row_specInfo"/>
  <input type="hidden" id="mall_goods_btn_addSpec"/>
  <input type="hidden" id="mall_goods_row_editSpec"/>
</div>
<div id="div_goods_spec_info" style="display:none;padding-top:2px">
  <div style="padding-top:0px;padding-bottom:2px;padding-left:3px">
    <span class="input-group-btn">
      <button type="button" class="btn btn-inverse btn-white" id="btnAddSpec" title="添加规格" permission='mall_goods_btn_addSpec' style="display:none"><span class="ace-icon fa fa-plus bigger-110"></span>添加规格</button>
      <button type="button" class="btn btn-inverse btn-white" id="btnRefreshSpec" title="刷新" permission='mall_goods_row_listSpecs' style="display:none"><span class="ace-icon fa fa-refresh"></span>刷新</button>
    </span>
  </div>
  <table id="listInfo" class="table table-striped table-bordered table-hover">
    <tbody>
      <tr>
        <td style="text-align:center;height:37px">正在加载……</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="div_goods_spec_edit" style="display:none;padding-top:2px">
  <form class="form-horizontal" id="form_goods_spec_edit" role="form">
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4">产品名称<span style="display:inline-block;width:7px"></span></div></label>
    <div class="col-sm-8">
      <div class="hr-4"></div>
      <input type="text" id="goods_name" readonly disabled placeholder="产品名称" class="form-control" maxlength="64" title="产品名称"/>
    </div>
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4">规格名称<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
    <div class="col-sm-8">
      <div class="hr-4"></div>
      <input type="text" id="size_name" placeholder="规格名称" class="form-control" maxlength="64" title="规格名称"/>
    </div>
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4">销售价格<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
    <div class="col-sm-8">
      <div class="hr-4"></div>
      <input type="text" id="size_price" placeholder="销售价格" class="form-control" maxlength="15" oninput="value=value.replace(/[^\d.]/g,'')" title="销售价格"/>
    </div>
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4">市场价格<span style="display:inline-block;width:7px"></span></div></label>
    <div class="col-sm-8">
      <div class="hr-4"></div>
      <input type="text" id="market" placeholder="市场价格，为空则和销售价格一样" class="form-control" maxlength="15" oninput="value=value.replace(/[^\d.]/g,'')" title="市场价格，为空则和销售价格一样"/>
    </div>
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4" id="added_required_spec_img">规格图<span style="display:inline-block;width:7px"></span></div></label>
    <div class="col-sm-8" id="spec_img_parent" >
      <div class="hr-4"></div>
      <input type="file" id="spec_img" placeholder="规格图" class="form-control" title="请选择规格图"/>
    </div>
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4" id="added_required_inventory">库存量<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
    <div class="col-sm-8">
      <div class="hr-4"></div>
      <input type="text" id="size_inventory" placeholder="商品的库存量" class="form-control" maxlength="10" title="商品的库存量"/>
    </div>
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4">排序号<span style="display:inline-block;width:7px"></span></div></label>
    <div class="col-sm-8" style="margin-bottom:6px">
      <div class="hr-4"></div>
      <input type="text" id="size_order_by" placeholder="排序号" class="form-control" maxlength="5" title="排序号" oninput="value=value.replace(/[^\d]/g,'')"/>
    </div>
  </form>
</div>
<div class="list-group" id="div_show_html_template" style="display:none;padding-top:2px;margin-bottom:2px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;"></div>
<script type="text/javascript">
  ;(function($){
    var tableDom = '#tableListGoods';
    var urlRoute = '/mallGoods/';/*请求controller层的url*/
    var getList = urlRoute + 'listData';/*获取数据列表*/
    var urlAdd = urlRoute + 'add';/*添加*/
    var urlEdit = urlRoute + 'edit';/*编辑*/
    var urlQueryById = urlRoute + 'queryById';/*根据id查询对应的数据*/
    var urlUpdateValid = urlRoute + 'editValid';/*上架或下架*/
    var urlDelByKeys = urlRoute + 'delByKeys';/*批量删除*/
    var getCategory = urlRoute + 'getCategory';/*获取字段category的下拉框列动态值选项的数据*/
    var urlGetGoodsSpecList = urlRoute + 'getGoodsSpecList';/*获取商品规格列表*/
    var urlQuerySpecInfo = urlRoute + 'querySpecInfo';/*获取商品规格详情*/
    var urlAddSpec = urlRoute + 'addGoodSpec';/*添加商品规格*/
    var urlEditSpec = urlRoute + 'editGoodSpec';/*编辑商品规格*/
    var urlSpecStatus = urlRoute + 'editSpecStatus';/*隐藏|显示商品规格*/
    var stateOriginal = {};
    var thisTable = null;
    /**商品规格对应的组织机构的id*/
    thisPage = {
      init : function(){
        this.initTable();
        this.createDropdown();
        this.initDom();
        this.addEvent();
      },
      initDom : function(){
        winFn.initFileShoose('#thumbnail',['jpg','JPG','jpeg','JPEG','png','PNG','svg','SVG'],'请选择商品图片(单张)');
        winFn.initFileShoose('#cover',['jpg','JPG','jpeg','JPEG','png','PNG','svg','SVG'],'请选择商品介绍图(多张)');
        winFn.initFileShoose('#spec_img',['jpg','JPG','jpeg','JPEG','png','PNG','svg','SVG'],'请选择规格图');
      },
      createDropdown : function(){
        //获取字段category的下拉框列动态值选项的数据
        layerFn.ajaxGetResult(getCategory,{},function(data){
          if(AppKey.code.code200 == data.code){
            winFn.initDropdown(data.data,'#ulDynamic_category','#category','#labelDynamic_category','请选择商品分类');
          }else{
            winFn.initDropdown([],'#ulDynamic_category','#category','#labelDynamic_category',data.msg);
          }
        });
      },
      addEvent : function(){
        $(tableDom +' tbody').on('dblclick','td:not(:first-child,:last-child)',function(){//除去每行的第一个和最后一个单元格均可双击事件
          if(verifyFn.inputRequired('#mall_goods_row_edit')){
            return;
          }
          thisPage.trDblclick(thisTable.row($(this).parent()).data());
        });
        $('#btnAdd').on('click', function(){
          thisPage.edit();
        });
        //搜索按钮
        $('#btnSearch').on('click', function(){
          thisPage.search(true);
        });
        //刷新按钮
        $('#btnRefreshSpec').on('click', function(){
          $('#listInfo').DataTable().ajax.reload(null,false);//编辑时成功重新加载表数据(分页页码保留);
        });
        //重置按钮
        $('#btnReset').on('click', function(){
          $('#key_name').val('');
          $('#labelSearch_valid').text('全部状态');
          $('#key_valid').val('');
        });
        //按钮组-自定义显示列
        $('#iconColumn').parent().parent().on('click', function(){
          pageDataTable.columnCustom(thisTable, tableDom,'#divKeyColumns');
        });
        //按钮组-搜索
        $('#iconRefresh').parent().parent().on('click', function(){
          thisPage.search(true);
        });
        $('#btnDel').on('click', function(){
          thisPage.delKeys();
        });
        $('#btnAddSpec').on('click', function(){
          thisPage.rowEditSpec();
        });
      },
      /**获取已选中的主键集合,用法:var kids = thisPage.getKeyIds();if(kids == null || kids == ''){layerFn.alert('请选择要操作的数据', AppKey.code.code199);return;}*/
      getKeyIds : function(){
        var arrays = thisTable.rows({selected : true}).data();//获取已勾选的数据行
        if(arrays.length == 0){
          return null;
        }
        var kids = '';
        for(var i = 0; i < arrays.length; i++){
          var value = arrays[i].kid;
          if(value != ''){
            if(kids.length > 0) kids += ",";
            kids += value;
          }
        }
        return kids;
      },
      /*批量删除*/
      delKeys : function(){
        if(verifyFn.inputCheck('#mall_goods_btn_delByKeys','没有删除操作权限')) return;
        var kids = thisPage.getKeyIds();
        if(kids == null || kids == ''){
          layerFn.alert('请选择要删除的数据!', AppKey.code.code199);
          return;
        }
        layerFn.confirm('将要删除[' + kids.split(',').length + ']条数据且是无法恢复,确定要继续吗?', function(){
          layerFn.delBatchHint(urlDelByKeys, kids, function(data){//后端可直接使用 final Long[] kids 接收参数的
            $(tableDom+'_wrapper table thead tr th:eq(0) label input[type="checkbox"]').prop("checked",false);
            thisPage.complete(data, null, true);
          });
        });
      },
      //点击各个标签
      changeTabs : function(tab){
        switch (tab){
          case 1:
            break;
          case 2:
            break;
          case 3:
            break;
          default:
            break;
        }
      },
      //thisPage.selectTab(0);选中第1个
      selectTab : function(tab){
        $("ul.nav-tabs li").each(function(){
          $(this).removeClass("active");//移除所有的类的样式
        });
        $("ul.nav-tabs li").each(function(index){
          if(index == tab){
            $(this).addClass("active");
          }
        });
        //tab切换容器,> 是获取所有的下一级,不是所有的子孙节点
        $('#tab_content_mode_sales > div').each(function(index){
          var _id = $(this).attr('id');
          if(_id != ''){
            $('#'+_id).removeAttr("class");
            if(0 == index){
              $('#'+_id).addClass("tab-pane fade in active");
            }
            $('#'+_id).addClass("tab-pane fade");
          }
        });
      },
      initTable : function(){
        var optsVisible = getOptsVisible('mall_goods_row');//确定是否要显示操作选项,若是多个按钮权限时以逗号,隔开
        var optsBatchBtn = getOptsVisible('mall_goods_btn_delByKeys');//是否有批量操作的权限,若是多个按钮权限时以逗号,隔开
        var aoColumns = [];
        if(optsBatchBtn){
          aoColumns.push({
            sortable : false,
            data : "kid",
            width : "38px",
            class : "center",
            visible : true,
            title : '<label title="全选|不选"><input type="checkbox" class="ace" /><span class="lbl"></span></label>'
          });
        }
        aoColumns.push({
          data : "goodsName",
          sortable : false,
          title : "商品名称"
        });
        aoColumns.push({
          data : "categoryName",
          sortable : false,
          title : "分类名称"
        });
        aoColumns.push({
          data : "sort",
          sortable : false,
          class : 'hidden-480',
          width: "64px",
          title : "排序号"
        });
        aoColumns.push({
          data : "valid",
          sortable : false,
          title : "销售状态",
          width: "64px",
          render : function(value,type,row,meta){
            switch (value){
              case 1:
                return "上架";
              case 0:
                return "下架";
              default:
                return "";
            }
          }
        });
        aoColumns.push({
          data : "add_date",
          sortable : false,
          title : "发布时间",
          class : 'text-center',
          width: "121px",
          render : function(value){
            return winFn.formatDate(value,true);
          }
        });
        aoColumns.push({
          data : "modify_date",
          sortable : false,
          title : "更新时间",
          width: "121px",
          class : 'text-center',
          render : function(value){
            return winFn.formatDate(value,true);
          }
        });
        aoColumns.push({
          data : "_kid_more_",
          sortable : false,
          title : "<label style='color:#000' title='查看更多选项'>更多选项</label>",
          class : 'text-center',
          width: '95px',
          render : function(value,type,row,meta){
            var html = "<div style='margin:-10px -2px -10px -2px'><span class='input-group-btn'>";
            html += "<button data-toggle='dropdown' class='btn btn-primary btn-white dropdown-toggle' style='margin-left:0px;border:none' title='更多选项'>";
            html += "<span style='margin-left:-4px;margin-right:4px;padding-right:-20px'>更多选项</span>";
            html += "<i class='ace-icon fa fa-angle-down'></i>";
            html += "</button>";
            html += "<ul class='dropdown-menu dropdown-info dropdown-menu-right' style='margin-left:-1px;width:95px;min-width:95px;margin-right:-2px'>";
            html += "<li style='display:none' permission='mall_goods_row_queryById' title='商品描述'><a href='javascript:thisPage.rowColumnDetails("+meta.row+",\"details\",1);'>商品描述</a></li>";
            html += "<li style='display:none' permission='mall_goods_row_queryById' title='注意事项'><a href='javascript:thisPage.rowColumnDetails("+meta.row+",\"tips\",1);'>注意事项</a></li>";
            html += "<li style='display:none' permission='mall_goods_row_queryById' title='商品图片'><a href='javascript:thisPage.rowColumnDetails("+meta.row+",\"thumbnail\",4);'>商品图片</a></li>";
            html += "<li style='display:none' permission='mall_goods_row_queryById' title='商品介绍图'><a href='javascript:thisPage.rowColumnDetails("+meta.row+",\"cover\",3);'>商品介绍图</a></li>";
            html += "</ul>";
            html += "</span>";
            html += "</div>";
            return html;
          }
        });
        if(optsVisible){
          aoColumns.push({
            data : "_kid_",
            width : "110px",
            class : 'text-center',
            title : "<label style='color:#000' title='单行操作'>操作选项</label>",
            sortable : false
          });
        }
        var columnDefs = [];
        if(optsBatchBtn){
          columnDefs.push({
            targets : 0,
            render : function(value,type,row,meta){
              return '<label title="选择|取消"><input type="checkbox" name="kid" value="'+ value +'" style="cursor:pointer;text-decoration:none;outline:none;"/><span class="lbl"></span></label>';
            }
          });
        }
        if(optsVisible){//是否来显示某列
          columnDefs.push({
            targets : -1,
            render : function(value,type,row,meta){
              return "<a title='编辑|修改' href='javascript:thisPage.rowEdit("+ meta.row +");' style='outline:none;text-decoration:none;color:#3b8cff;display:none' permission='mall_goods_row_edit'>编辑</a>" +
                "<a title='销售状态(上架|下架)' class='hidden-480' href='javascript:thisPage.rowValid("+ meta.row +");' style='outline:none;text-decoration:none;color:#e750f8;margin-left:6px;display:none' permission='mall_goods_row_valid'>"+(row.valid == 1 ? '下架' : '上架')+"</a>" +
                "<a title='查看规格' class='hidden-480' href='javascript:thisPage.rowSpec("+ meta.row +");' style='outline:none;text-decoration:none;color:#31bdec;margin-left:6px;display:none' permission='mall_goods_row_listSpecs'>规格</a>";
            }
          });
        }
        columnDefs.push({
          targets : optsBatchBtn ? [1,2,3,4,5,6,7] : [0,1,2,3,4,5,6,7],
          render : function(value,type,row,meta){
            return pageDataTable.formatColumn(value);
          }
        });
        columnDefs.push({
          visible : false,//列的隐藏显示
          targets : []//指定列索引
        });
        thisTable = pageDataTable.initDataTable({
          tableDom : tableDom,
          sAjaxSource : getList,
          fnServerParams : function(params){
            params.push(
              {"name":"deptId","value":winFn.getDomValue('#key_dept_id')},
              {"name":"name","value":winFn.getDomValue('#key_name')},
              {"name":"valid","value":winFn.getDomValue('#key_valid')},
              {"name":"deleted","value":winFn.getDomValue('#key_deleted')}
            );
          },
          aoColumns : aoColumns,
          columnDefs : columnDefs,
          complete : function(settings,data){},//仅执行一次
          footer : function(data,start,end,thLength){},//每次都会执行
          selected : function(selected){
            if(selected){
              $('#btnDel').removeAttr('disabled');
            }else{
              $('#btnDel').attr('disabled','disabled');
            }
          }
        });
        pageDataTable.buttons(thisTable);
        pageDataTable.action(thisTable);
        pageDataTable.select(thisTable, tableDom);
        pageDataTable.tooltip();
        $('.dataTables_scroll .dataTables_scrollBody').removeAttr('style');
      },
      //双击事件
      trDblclick : function(data){
        if(data){
          thisPage.edit(data.kid);
        }
      },
      //是否是搜索,是则搜索时则返回到第一页
      search : function(search){
        if(verifyFn.inputCheck('#mall_goods_btn_listData','没有操作权限')) return;
        $(tableDom + '_wrapper table input[type=checkbox]').prop('checked',false);//此行不需要,因为搜索时表格已重新渲染
        //thisTable.draw();保留
        if(search){
          $(tableDom).DataTable().ajax.reload();//编辑时成功会重载所有接口数据，返回到第一页
        }else{
          $(tableDom).DataTable().ajax.reload(null,false);//编辑时成功重新加载表数据(分页页码保留);
        }
      },
      resetForm : function(){
        winFn.clearFormData('#form_goods_edit',[{'labelDynamic_category':'选择商品分类'}],['default_size_name']);
      },
      edit : function(kid){
        var title = '添加';
        if(kid != null && kid.length > 0){
          if(verifyFn.inputCheck('#mall_goods_row_queryById','没有操作权限')) return;
          title = '编辑';
          layerFn.queryByIdHint(urlQueryById, kid, function(data){
            thisPage.openDialog(title, kid, data);
            //thisPage.editJson(data.data,['ad_img']);//仅在赋值后再执行此代码,更新优化-选项2
          });
        }else{
          thisPage.openDialog(title);
        }
      },
      //移除不需要对比的key(此方法可有可无)
      editJson : function(data,keys){
        if(keys){
          for(var h = 0; h < keys.length; h++){
            delete data[keys[h]];//删除key元素
          }
        }
        stateOriginal = data;
      },
      rowValid : function(rowIndex){
        if(verifyFn.inputCheck('#mall_goods_row_valid','没有操作权限')) return;
        var row = thisTable.row(rowIndex).data();
        var is = row.valid == 1;
        var deleted = is ? '下架' : '上架';
        var enabled = is ? 0 : 1;
        layerFn.confirm('['+row.goodsName+']确定要"'+deleted+'"操作吗?', function(){
          layerFn.submit(urlUpdateValid,{kid:row.kid,enabled:enabled},function(data){
            thisPage.complete(data,null,true);
          });
        });
      },
      openDialog : function(title, kid, map){
        var url = urlAdd;
        if(kid != null && kid.length > 0){
          url = urlEdit;
          $('#div_default_size').css("display","none");//编辑时隐藏
          if(verifyFn.inputNull('#mall_goods_row_edit','没有编辑权限')) return;
        }else{
          $('#div_default_size').css("display","");//新增时显示
          if(verifyFn.inputNull('#mall_goods_btn_add','没有添加权限')) return;
        }
        if(kid != null && kid.length > 0){
          $('#added_required_cover').html('介绍图<span style="display:inline-block;width:7px"></span>');
          $('#added_required_thumbnail').html('商品图片<span style="display:inline-block;width:7px"></span>');
        }else{
          $('#added_required_cover').html('介绍图<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span>');
          $('#added_required_thumbnail').html('商品图片<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span>');
        }
        layerFn.winKindEditor(title,'#div_goods_edit',['#details'],(map == null ? null : map.data), ['966px','640px'], function(layerIndex, layero){
          if(verifyFn.inputEmpty('#name')) return;
          if(verifyFn.inputNull('#category','请选择商品分类')) return;
          var is_added = kid == null || kid.length <= 0;
          if(is_added){
            if(verifyFn.inputNull('#thumbnail','请选择商品图片文件')) return;
            if(verifyFn.inputNull('#cover','请选择商品介绍图文件')) return;
            if(verifyFn.inputNull('#default_size_name','请输入商品规格的名称')) return;
            if(verifyFn.inputNull('#default_size_price','请输入商品规格的价格')) return;
            if(verifyFn.inputNull('#default_size_inventory','请输入商品规格的库存')) return;
          }
          if(verifyFn.inputNull('#details','商品描述不能为空')) return;
          var params = {
            name : winFn.getDomValue('#name',true),
            category : winFn.getDomValue('#category',true),
            tips : winFn.getDomValue('#tips',true),
            details : winFn.getDomValue('#details'),
            sort : winFn.getDomValue('#sort',true),
            kid : kid
          };
          if(is_added){
            params['size_name'] = winFn.getDomValue('#default_size_name',true);
            params['size_price'] = winFn.getDomValue('#default_size_price',true);
            params['size_inventory'] = winFn.getDomValue('#default_size_inventory',true);
          }
          var formData = new FormData();
          for(var key in params){
            formData.append(key,params[key]);
          }
          var file_thumbnail = document.getElementById("thumbnail").files[0];
          if(file_thumbnail){
            var mb = file_thumbnail.size / (1024 * 1024);//得到的MB,做文件大小限制
            if(mb > 3){
              layerFn.alert('商品缩略图已超过３ＭＢ',AppKey.code.code199);
              return;
            }
            formData.append("thumbnail",file_thumbnail);
          }else{
            formData.append("thumbnail",null);
          }
          var file_covers = document.getElementById("cover").files;//单个表单字段允许多个文件
          if(file_covers.length > 0){
            for(var h=0;h<file_covers.length;h++){
              var file = file_covers[h];
              var fs = file.size / (1024 * 1024);//得到的MB,做文件大小限制
              if(fs > 2){
                layerFn.alert('商品介绍图已超过２ＭＢ',AppKey.code.code199);
                return;
              }
              //var ft = file.type;//获取的是文件类型
              formData.append("cover"+h,file);//获取上传的多个文件
            }
          }else{
            formData.append("cover",null);
          }
          layerFn.formSubmit(url,formData,function(data){
            thisPage.complete(data,layerIndex,true);
          });
        });
        thisPage.resetForm();
        if(map != null){
          $.each(map.data,function(k,v){
            try{
              if(k == 'category'){
                winFn.editDropdown('#labelDynamic_category', v);
                $('#' + k).val(v);
                return true;
              }
              if(k == 'temp_thumbnail'){//保留,占位符,若使用到则删除前缀temp_即可
                //var jsonThumbnail = eval('(' + k + ')');文件上传字段类型为json类型
                //$('#thumbnail').attr('rel',v);//a标签,保留
                return true;
              }
              if(k == 'temp_cover'){//保留,占位符,若使用到则删除前缀temp_即可
                //var jsonCover = eval('(' + k + ')');文件上传字段类型为json类型
                //$('#cover').attr('rel',v);//a标签,保留
                return true;
              }
              /*if(k == '需要处理特殊字段field,如复选框或单选框'){
                $('#label_'+goods_id).addClass("hRadio_Checked").prev()[0].checked = true;//赋值,选中
                $('#label_'+goodsId).addClass("checked").prev()[0].checked = true;//赋值,选中
                return true;//跳出本次循环;false跳出循环
              }*/
              $('#' + k).val(v);//若是有问题则把这个放在最前面
            }catch(e){}
          });
        }
      },
      rowEdit : function(rowIndex){
        var row = thisTable.row(rowIndex).data();
        thisPage.edit(row.kid);
      },
      rowSpec : function(rowIndex){
        if(verifyFn.inputCheck('#mall_goods_row_listSpecs','没有操作权限')) return;
        var row = thisTable.row(rowIndex).data();
        this.goodsSpecId = row.kid;
        this.goodsSpecDeleted = row.deleted == 0;//是否已删除
        $('#goods_name').val(row.goodsName);
        thisPage.initTableDialog(row.kid,row.goodsName);
      },
      initTableDialog : function(kid,name){
        this.dialogTable = pageDataTable.initDataTable({
          complete : function(settings,data){
            layerFn.winDom(name +'商品规格','#div_goods_spec_info',['810px','600px'],function(layerIndex,layero){},'关闭');
          },
          dom : "t<'row'<'col-sm-6'i><'col-sm-6'p>>",
          iDisplayLength : 25,
          tableDom : '#listInfo',
          sAjaxSource : urlGetGoodsSpecList,
          fnServerParams : function(params){
            params.push(
              {"name":"goods_id","value":kid}
            );
          },          
          aoColumns : [
            {
              mData : "name",
              bSortable : false,
              sTitle : "规格名称"
            },
            {
              mData : "price",
              bSortable : false,
              width:"70px",
              sTitle : "积分价"
            },
            {
              mData : "market",
              bSortable : false,
              width:"70px",
              sTitle : "市场价",
              render : function(value,type,row,meta){
                return value ? value : row.price;
              }
            },
            {
              mData : "inventory",
              bSortable : false,
              width:"70px",
              sTitle : "库存量",
              render : function(value,type,row,meta){
                return value ? value : '无限量';
              }
            },
            {
              mData : "deleted",
              bSortable : false,
              sTitle : "销售状态",
              class : 'text-center',
              width:"60px",
              render : function(value,type,row,meta){
                switch (value){
                  case 1:
                    return "显示";
                  case 0:
                    return "隐藏";
                  default:
                    return "";
                }
              }
            },
            {
              mData : "order_by",
              bSortable : false,
              width:"44px",
              class : 'text-center',
              sTitle : "排序号"
            },
            {
              mData : "_size_key_",
              bSortable : false,
              class : 'text-center',
              width:"76px",
              title : "<label style='color:#000' title='单行操作'>操作选项</label>"
            }
          ],
          columnDefs : [
            {
              targets : -1,
              render : function(value,type,row,meta){
                return "<a title='编辑|修改' href='javascript:thisPage.rowEditSpec(\""+ row.kid +"\");' style='outline:none;text-decoration: none;color:#3b8cff;display:none' permission='mall_goods_row_editSpec'>编辑</a>"+
                  "<a title='隐藏|显示规格' class='hidden-480' href='javascript:thisPage.rowSpecStatus("+ meta.row +");' style='outline:none;text-decoration: none;color:#f00;margin-left:4px;display:none' permission='mall_goods_row_specStatus'>"+(row.deleted == 1 ? '隐藏' : '显示')+"</a>";
              }
            }
          ]
        });
      },
      rowEditSpec : function(kid){
        var title = '添加规格';
        if(kid != null && kid.length > 0){
          if(verifyFn.inputCheck('#mall_goods_row_specInfo','没有操作权限')) return;
          title = '编辑规格';
          layerFn.queryByIdHint(urlQuerySpecInfo, kid, function(data){
            thisPage.openGoodsSpecDialog(title, kid, data);
          });
        }else{
          if(this.goodsSpecDeleted){
            layerFn.alert('商品已删除隐藏，无需添加规格',AppKey.code.code199);
            return;
          }
          thisPage.openGoodsSpecDialog(title);
        }
      },
      rowSpecStatus : function(rowIndex){
        var row = this.dialogTable.row(rowIndex).data();
        var is = row.deleted == 0;
        var _display = is ? '显示' : '隐藏';
        var enabled = is ? 1 : 0;
        layerFn.confirm('确定要‘'+_display+'’规格['+row.name+']吗？',function(){
          layerFn.submit(urlSpecStatus,{kid:row.kid,enabled:enabled,goodsId:row.goods_id},function(data){
            thisPage.completeSpec(data,null,true);
          });
        });
      },
      openGoodsSpecDialog : function(title, kid, map){
        var url = urlAddSpec;
        var bl = kid != null && kid.length > 0;
        if(bl){
          url = urlEditSpec;
          if(verifyFn.inputNull('#mall_goods_row_editSpec','没有编辑权限')) return;
        }else{
          if(verifyFn.inputNull('#mall_goods_btn_addSpec','没有添加权限')) return;
        }
        if(bl){
          $('#added_required_spec_img').html('规格图<span style="display:inline-block;width:7px"></span>');
        }else{
          $('#added_required_spec_img').html('规格图<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span>');
        }
        var _this = this;
        layerFn.addOrEdit(title,'#div_goods_spec_edit', ['500px','360px'], function(layerIndex){
          if(verifyFn.inputEmpty('#size_name')) return;
          if(verifyFn.inputEmpty('#size_price')) return;
          if(verifyFn.inputEmpty('#size_inventory')) return;
          if(!bl){
            var spec_img = document.getElementById("spec_img").files[0];
            if(spec_img == undefined){
              layerFn.alert('请选择商品的规格图',AppKey.code.code199);
              return;
            }
          }
          var params = {
            size_name : winFn.getDomValue('#size_name',true),
            size_price : winFn.getDomValue('#size_price',true),
            market : winFn.getDomValue('#market',true),
            size_inventory : winFn.getDomValue('#size_inventory',true),
            order_by : winFn.getDomValue('#size_order_by',true),
            goods_id : _this.goodsSpecId,
            kid : kid
          };
          var formData = new FormData();
          for(var key in params){
            formData.append(key,params[key]);
          }
          var file_spec_img = document.getElementById("spec_img").files[0];
          if(file_spec_img){
            var mb = file_spec_img.size / (1024 * 1024);//得到的MB,做文件大小限制
            if(mb > 1){
              layerFn.alert('规格图已超过１ＭＢ',AppKey.code.code199);
              return;
            }
            formData.append("spec_img",file_spec_img);
          }else{
            formData.append("spec_img",null);
          }
          layerFn.formSubmit(url,formData,function(data){
            thisPage.completeSpec(data,layerIndex,true);
          });
        });
        thisPage.resetSpecForm();
        if(map != null){
          $.each(map.data,function(k,v){
            try{
              $('#' + k).val(v);//若是有问题则把这个放在最前面
            }catch(e){}
          });
        }
      },
      resetSpecForm : function(){
        winFn.clearFormData('#form_goods_spec_edit',null,['size_order_by','goods_name']);
      },
      //column指定列名,type:1是普通的文本;2json对象里的value[字段已做转换 JSON_UNQUOTE(JSON_EXTRACT(icon,'$.urlFile')) as icon];3是json对象里含json对象;4是json对象[字段未做转换];5是打印
      rowColumnDetails : function(rowIndex,column,type){
        var row = thisTable.row(rowIndex).data();
        var columnValue = row[column];
        if(columnValue != undefined){
          switch (type){
            case 1:
              layerFn.viewValue(columnValue || '暂无数据','430px');
              break;
            case 2:
              window.open(webFiles+columnValue,'_blank').location;
              break;
            case 3:
              winFn.showFiles('#div_show_html_template',columnValue,column,'originalName');//单个文件域含多个文件
              break;
            case 4:
              var objs = eval('('+columnValue+')');
              if(objs != undefined && objs.urlFile != undefined){
                window.open(webFiles+objs.urlFile,'_blank').location;
              }else{
                layerFn.alert('暂无数据',AppKey.code.code199);
              }
              break;
            case 5:
              var obj = eval('('+columnValue+')');
              if(obj != undefined && obj.urlFile != undefined){
                sessionStorage.setItem('file_url',webFiles+obj.urlFile);
                window.open('print.html','_blank').location;
              }else{
                layerFn.alert('暂无数据',AppKey.code.code199);
              }
              break;
            default:
              layerFn.alert('参数有误',AppKey.code.code199);
              break;
          }
        }else{
          layerFn.alert('暂无数据',AppKey.code.code199);
        }
      },
      complete : function(data,index,search){
        try{
          if(index){
            layerFn.closeIndex(index);
          }
          if(search){
            thisPage.search();
          }
          if(data){
            layerFn.handleResult(data.msg,data.code);
          }
        }catch(e){}
      },
      completeSpec : function(data,index,search){
        try{
          if(index){
            layerFn.closeIndex(index);
          }
          if(search){
            this.dialogTable.draw();
          }
          if(data){
            layerFn.handleResult(data.msg,data.code);
          }
        }catch(e){}
      }
    };
    thisPage.init();
    $('script').remove();
  })(jQuery);
</script>